package com.jt.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author 刘昱江
 * 时间 2021/2/23
 */
@Component
@Slf4j
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("入库操作");
        Date date = new Date();
        this.setFieldValByName("created",date , metaObject);
        this.setFieldValByName("updated",date , metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("更新操作");
        this.setFieldValByName("updated", new Date() , metaObject);
    }
}
